package com.yx.sys.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.yx.common.vo.Result;
import com.yx.sys.entity.Verification;
import com.yx.sys.service.IVerificationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Api(tags = {"验证码接口列表"})
@RestController
@RequestMapping("/verification")
public class VerificationController {

    @Autowired
    private IVerificationService verificationService;
    @ApiOperation("发送邮箱验证码")
    @GetMapping("/sendCode")
    public Result<String> sendCode(String uEmail){
        verificationService.sendCode(uEmail);
        return Result.success("邮件已发送，注意查收");
    }

    @ApiOperation("校验验证码是否正确")
    @GetMapping("/check")
    public Result<String> checkCode(String email,String code){
        System.out.println(email);
        System.out.println(code);
        QueryWrapper<Verification> wrapper = new QueryWrapper<>();
        wrapper.eq("email",email);
        Verification one = verificationService.getOne(wrapper);
        if(one!=null){
            System.out.println(one);
            System.out.println(one.getYzm().equals(code));
            if(one.getYzm().equals(code)){
                return Result.success(null);
            }else{
                return Result.success("验证码输入错误，请仔细检查");
            }
        }
        return Result.success(null);
    }
}
